<template>
    <div>
        <van-nav-bar title="设置密码" class="navbar" left-text="返回" left-arrow @click-left="onClickLeft" />
        <div class="register-form">
        <div class="form-input">
            <van-field v-model="password" :type="!type ? 'password' : 'text'" placeholder="请设置6-20位登录密码"
                 @click-right-icon="type = !type" clearable :right-icon="type ? 'eye-o' : 'closed-eye'" />
        </div>
        <div class="form-btn">
            <van-button @click="finish" :disabled="!flag" color="linear-gradient(to right, #ee0a24, #ff6034)" block round>完成</van-button>
        </div>
      </div>
    </div>
</template>

<script>
import { doZhuce } from '@/api/user';
    export default {
        data(){
            return{
                tel:'',
                password:'123456',
                type:false
            }
        },
        computed:{
            flag(){
               return /^\d{6}$/.test(this.password)
            }
        },
        created(){
            this.tel=localStorage.getItem('tel')
        },
        methods:{
            onClickLeft(){
                history.back()
            },
            finish(){
                // console.log(111);
                doZhuce({loginname:this.tel,password:this.password}).then(res=>{
                   if (res.data.code!=200) return showToast('注册失败')
                   this.$router.push('/denglu')
                   console.log(111);
                })
                
            }
        }
    }
</script>

<style lang="less" scoped>

</style>